﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ChartSharp
{
    public abstract class BaseChart
    {
        private const string BASE_URL = "http://chart.apis.google.com/chart?";

        protected Type _type;
        protected Size _size;

        public BaseChart(Type type)
        {
            _type = type;
        }

        public BaseChart(Type type, Size size)
        {
            _type = type;
            _size = size;
        }

        public override string ToString()
        {
            FieldInfo[] members = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance);

            StringBuilder builder = new StringBuilder();
            builder.Append(BaseChart.BASE_URL);

            members.ToList().ForEach((member) =>
            {
                var param = member.GetValue(this) as ChartParam;

                if (param != null)
                {
                    param.Build(builder);
                    builder.Append("&");
                }
            });

            if (builder.Length > 0)
            {
                builder.Length--;
            }

            return builder.ToString();
        }
    }
}
